var events = require("events");
var emitter = new events.EventEmitter();

//添加观察者1
var listener1 = function listener1() {
    console.log("listener1收到收到事件");
};
var listener2 = function listener2() {
    console.log("listener2收到收到事件");
};

emitter.addListener("event", listener1);
emitter.addListener("event", listener1);
emitter.addListener("event", listener2);
emitter.on("event", listener1);
emitter.on("event", listener2);
emitter.on("event", listener2);

//观察者数量
var count = events.listenerCount(emitter, "event");
console.log("listener count " + count);
emitter.emit("event");

//只能移除一个观察者
emitter.removeListener("event",listener1);
count = events.listenerCount(emitter, "event");
console.log("listener count " + count);
emitter.emit("event");
//直接报错
emitter.emit("error");

